/*!
 Temelia - Binary tree implementation source file.

 Copyright (C) 2008, 2009 Ceata (http://ceata.org/proiecte/temelia).

 @author Dascalu Laurentiu

 This program is free software; you can redistribute it and
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 3
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "include/binary_tree.h"
#include "include/common.h"
#include "include/stack.h"

stack_t iterating_handlers = (stack_t) 0;
stack_t compare_stack = (stack_t) 0;

// one to one methods calling. Wrapper over internal binary tree methods.

binary_tree_t binary_tree_new(void *key)
{
	return _binary_tree_new(key);
}

void binary_tree_delete_node(binary_tree_node_t node)
{
	_binary_tree_delete_node(node);
}

void binary_tree_delete(binary_tree_t tree)
{
	_binary_tree_delete(tree);
}

int binary_tree_compare_trees(binary_tree_t bt1, binary_tree_t bt2,
		int compare(void *x, void *y, void *context), void *context)
{
	return _binary_tree_compare_trees(bt1, bt2, compare, context);
}

int binary_tree_is_empty(binary_tree_t tree)
{
	return _binary_tree_is_empty(tree);
}

int binary_tree_is_leaf(binary_tree_t node)
{
	return _binary_tree_leaf(node);
}

int binary_tree_get_size(binary_tree_t tree)
{
	return _binary_tree_get_size(tree);
}

binary_tree_t binary_tree_get_root(binary_tree_t node)
{
	return _binary_tree_get_root(node);
}

void *binary_tree_get_key(binary_tree_t node)
{
	return _binary_tree_get_key(node);
}

void binary_tree_set_key(binary_tree_t node, void *key)
{
	_binary_tree_set_key(node, key);
}

binary_tree_t binary_tree_get_parent(binary_tree_t node)
{
	return _binary_tree_get_parent(node);
}

void binary_tree_set_parent(binary_tree_t node, binary_tree_t parent, int dir)
{
	_binary_tree_set_parent(node, parent, dir);
}

binary_tree_t binary_tree_get_left_child(binary_tree_t node)
{
	return _binary_tree_get_left_child(node);
}

void binary_tree_set_left_child(binary_tree_t node, binary_tree_t child)
{
	_binary_tree_set_left_child(node, child);
}

binary_tree_t binary_tree_get_right_child(binary_tree_t node)
{
	return _binary_tree_get_right_child(node);
}

void binary_tree_set_right_child(binary_tree_t node, binary_tree_t child)
{
	_binary_tree_set_right_child(node, child);
}

void binary_tree_join(binary_tree_t parent, binary_tree_t left,
		binary_tree_t right)
{
	_binary_tree_join(parent, left, right);
}

void binary_tree_split(binary_tree_t parent, binary_tree_t *left,
		binary_tree_t *right)
{
	_binary_tree_split(parent, left, right);
}

binary_tree_t binary_tree_create_node(binary_tree_t parent, binary_tree_t left,
		binary_tree_t right, void *key, int dir)
{
	return _binary_tree_create_node(parent, left, right, key, dir);
}

int binary_tree_get_height(binary_tree_t tree)
{
	return _binary_tree_get_height(tree);
}

int binary_tree_get_depth(binary_tree_t node)
{
	return _binary_tree_get_depth(node);
}

void binary_tree_preorder(binary_tree_t tree, void key_handler(void *key,
		void *context), void *context)
{
	_binary_tree_preorder(tree, key_handler, context);
}

void binary_tree_inorder(binary_tree_t tree, void key_handler(void *key,
		void *context), void *context)
{
	_binary_tree_inorder(tree, key_handler, context);
}

void binary_tree_reverse_inorder(binary_tree_t tree, void key_handler(
		void *key, void *context), void *context)
{
	_binary_tree_reverse_inorder(tree, key_handler, context);
}

void binary_tree_postorder(binary_tree_t tree, void key_handler(void *key,
		void *context), void *context)
{
	_binary_tree_postorder(tree, key_handler, context);
}

void binary_tree_level_order(binary_tree_t tree, void key_handler(void *key,
		void *context), void *context)
{
	_binary_tree_level_order(tree, key_handler, context);
}

void binary_tree_show_indented(binary_tree_t tree, void key_handler(void *key,
		int level, void *context), void *context)
{
	_binary_tree_show_indented(tree, key_handler, context, 0);
}
